package com.neugh.controller;


import com.neugh.service.OrdeService;
import com.neugh.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sot
 * @since 2020-05-15
 */
@Controller
public class ShopController {

    @Autowired
    ShopService shopService;

    @Autowired
    OrdeService ordeService;

    @RequestMapping("/goodsdetail")
    public String goodsdetail(int id, Model model, String shopDetails){
        model.addAttribute("shop",shopService.selectById(id));
        model.addAttribute("houList",shopService.selectHouShop());
        String [] imgs = shopDetails.split(",");

        List<String> imgList = new ArrayList<String>();
        for(int i = 0;i<imgs.length;i++){
            imgList.add(imgs[i]);
        }
        model.addAttribute("imgList",imgList);
        System.out.println(imgList);
        System.out.println(shopService.selectHouShop());
        model.addAttribute("ordeList",ordeService.selectByIdOrde(id));
        return "goodsdetail";
    }

    @GetMapping("myorder")
    public String myorder(Integer orderTypeId, Model model){
        model.addAttribute("ordeList",shopService.selectAllorder(orderTypeId));
        model.addAttribute("shopList",shopService.seleShop(orderTypeId));
        return "myorder";
    }

}

